//package com.tcm.order.service.task;
//
//import cn.hutool.core.util.NumberUtil;
//import com.base.core.lang.DateUtils;
//import com.base.core.utils.GeneratorUtils;
//import com.base.genid.generator.UidGenerator;
//import com.tcm.order.entity.Order;
//import com.tcm.order.entity.OrderBill;
//import com.tcm.order.dao.mapper.OrderBillMapper;
//import com.tcm.order.dao.mapper.OrderMapper;
//import com.tcm.order.service.OrderBillService;
//import org.apache.dubbo.config.annotation.DubboReference;
//import org.apache.dubbo.config.annotation.DubboService;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import java.math.BigDecimal;
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//import java.util.List;
//
//@DubboService(version = "0.0.1-alpha", timeout = 6000, retries = 3, delay = -1)
//public class OrderBillServiceImpl implements OrderBillService {
//
//    @Autowired
//    private OrderMapper orderMapper;
//
//    @Autowired
//    private OrderBillMapper orderBillMapper;
//
//    @DubboReference(version = "0.0.1-beta",group = "cached-uid",timeout = 6000, check = false,retries = 3)
//    private UidGenerator uidGenerator;
//
//    /**
//     * 机器号，后期优化需要写入到配置中
//     */
//    private String machineNo = "01";
//    /**
//     * 环境编号，后期需要优化需要写入到配置中
//     */
//    private String env = "1";
//
//    @Override
//    public void create() {
//
//        //获取一个月之内未结算的订单
//        String startTime = DateUtils.getPrevMonthFirstDay();
//        String endTime = DateUtils.getPrevMonthLastDay();
//
//        List<Order> orderList = orderMapper.selectSettleStore(startTime,endTime);
//
//        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyy-MM-dd HH:ii:ss");
//        LocalDateTime sd = LocalDateTime.parse(startTime,df);
//        LocalDateTime ed = LocalDateTime.parse(endTime,df);
//        LocalDateTime now = LocalDateTime.now();
//        for(Order store : orderList){
//            //得出金额
//            Order orderMoney = orderMapper.selectSettleMoney(startTime,endTime,store.getStoreId());
//
//            OrderBill orderBill = new OrderBill();
//            orderBill.setId(uidGenerator.getUID());
//            orderBill.setSettleSn(GeneratorUtils.genOrderId(machineNo, env));
//            orderBill.setStartDate(sd);
//            orderBill.setEndDate(ed);
//            orderBill.setOrderTotals(orderMoney.getTotalMoney());
//            orderBill.setShippingTotals(orderMoney.getLogisticsFee());
//            //药房分成
//            BigDecimal result_totals = NumberUtil.mul(new BigDecimal(configService.findValue("settlement_pharmacy", "0.25")),
//                    orderMoney.getTotalMoney());
//            orderBill.setResultTotals(result_totals);
//            orderBill.setStoreId(store.getStoreId());
//            orderBill.setCreateTime(now);
//            orderBill.setUpdateTime(now);
//            orderBillMapper.insert(orderBill);
//            //更新状态
//            orderMapper.updateSettleOrder(startTime,endTime,store.getStoreId(),now);
//
//        }
//
//    }
//
//    @Override
//    public void insert(OrderBill orderBill) {
//        orderBillMapper.insert(orderBill);
//    }
//
//
//
//
//}
